#[macro_use] extern crate structopt;
use usrtrust::{Environment,SysBlocks};
use usrtrust::{PLLExchange,PLL};
use std::path::{Path};
use std::io::{Result};
use structopt::StructOpt;

#[derive(Debug, StructOpt)]
#[structopt(name = "ClockPLLSet", about = "Setting pll parameter.")]
struct Opt {
    /// 0 order
    #[structopt(short = "0", long = "a0", default_value = "1e-10")]
    a0: f64,
    /// 1 order
    #[structopt(short = "1", long = "a1", default_value = "3e-12")]
    a1: f64,
}

fn main() -> Result<()> {
    let opt = Opt::from_args();
    let e = Environment::from_dir(Path::new("/tmp/usrtos"))?;
    let fsys = e.find("system_block")?;
    println!("{}",fsys);
    let mut sys = SysBlocks::new(fsys)?;
    let mut pllex = sys.get_items::<PLLExchange>("pll_parameter")?;
    PLL::to_data((opt.a0,opt.a1),&mut pllex);
    Ok(())
}